<?php

namespace App\Listeners;

use App\Events\Event;
use App\Events\TeacherEvent;
use App\Events\StudentEvent;


class StudentListener extends Listener
{
    /**
     * @param TeacherEvent $event
     */
    public function handle(StudentEvent $event)
    {
        switch($event->action)
        {
            case Event::CREATE:
                $this->create($event); break;
            case Event::UPDATE:
                $this->update($event); break;
            case Event::DELETE:
                $this->delete($event); break;
            default: break;
        }
    }


    /**
     * 注册学生
     * @param $event
     */
    protected function create(StudentEvent $event)
    {
        try{
            $this->register($event->telephone,$event->nickname,$event->password);
        }catch (\Exception $e){
            throw $e;
        }
    }


    /**
     * 修改学生信息
     * @param $event
     */
    protected function update(StudentEvent $event)
    {
        try{
            $this->editUser($event->telephone,$event->nickname);
        }catch (\Exception $e){
            throw $e;
        }
    }


    /**
     * 删除
     * @param $event
     */
    protected function delete(StudentEvent $event)
    {

    }

}
